<?php

namespace App\Admin\Controllers;

use App\Model\Sncode;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class SncodeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'Sncode';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        $status = [
            0 => '未领取',
            1 => '已领取'
        ];
        $grid = new Grid(new Sncode());

        $grid->column('id', __('Id'))->sortable();
        $grid->column('sn', __('Sn'));
        $grid->column('rmb', __('金额'));
        $grid->column('user.name', __('领取者'));
        $grid->column('receive_time', __('领取时间'));
        $grid->column('batch.name', __('所属批次'));
        $grid->column('status', __('状态'))-> using($status)->label([0 => 'default',
            1 => 'success'])->filter($status);
        $grid->column('comment', __('备注'));
//        $grid->column('created_at', __('Created at'));
//        $grid->column('updated_at', __('Updated at'));
        $grid->disableCreateButton();
        $grid->disableActions();
        $grid->paginate(50);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Sncode::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('sn', __('Sn'));
        $show->field('rmb', __('金额'));
        $show->field('status', __('状态'));
        $show->field('user_id', __('领取者'));
        $show->field('receive_time', __('领取时间'));
        $show->field('salt', __('Salt'));
        $show->field('batch_id', __('B所属批次'));
        $show->field('comment', __('备注'));
//        $show->field('created_at', __('Created at'));
//        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Sncode());

        $form->text('sn', __('Sn'));
        $form->text('rmb', __('金额'));
        $form->text('status', __('状态'));
        $form->text('user_id', __('领取者'));
        $form->datetime('receive_time', __('领取时间'))->default(date('Y-m-d H:i:s'));
        $form->text('batch', __('所属批次'));
        $form->text('comment', __('备注'));

        $form->tools(function (Form\Tools $tools) {

            // 去掉`列表`按钮
            $tools->disableList();

            // 去掉`删除`按钮
            $tools->disableDelete();

            // 去掉`查看`按钮
            $tools->disableView();

        });
        $form->footer(function ($footer) {

            // 去掉`重置`按钮
            $footer->disableReset();

            // 去掉`提交`按钮
            $footer->disableSubmit();

            // 去掉`查看`checkbox
            $footer->disableViewCheck();

            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();

            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });

        return $form;
    }
}
